package com.xiaoqi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xiaoqi.dao.MemberDao;
import com.xiaoqi.pojo.Member;
import com.xiaoqi.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author PC
 * creationTime: 2022/11/22 12:40
 */

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    /**
     * 根据电话号码查找会员信息
     * @param telephone
     * @return
     */
    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }
    /**
     * 新增会员信息
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 根据日期统计指定日期之前的会员数
     */
    @Override
    public List<Integer> findMemberCountBeforeDate(List<String> months) {
        //返回List
        List<Integer> memberCount = new ArrayList<>();
        //变量月份查询每个月之前总共有多少个会员
        for (String month : months) {
            //将查询结果加入List
            Integer memberCountBeforeDate = memberDao.findMemberCountBeforeDate(month + "-01");
            memberCount.add(memberCountBeforeDate);
        }

        return memberCount;
    }

    /**
     * 查询会员总数
     */
    @Override
    public Integer findMemberTotalCount() {
        return memberDao.findMemberTotalCount();
    }
    /**
     * 统计某一天新增会员数量
     */
    @Override
    public Integer findMemberCountByDate(String date) {
        return memberDao.findMemberCountByDate(date);
    }

    /**
     * 查询当月新增会员数量
     * @return
     */
    @Override
    public Integer findMemberByMonthCount(String date) {
        return memberDao.findMemberByMonthCount(date);
    }

    /**
     * 查询当周新增会员数量
     * @return
     */
    @Override
    public Integer findMemberByWeekCount(String date) {
        return memberDao.findMemberByWeekCount(date);
    }
}
